﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestSystem.Domain.Abstract;
using TestSystem.Domain.DAL;
using TestSystem.Domain.Entities.Position;

namespace TestSystem.Domain.Repositories
{
    public class PositionRepository : IPositionRepository
    {
        private TestSystemContext dbContext = new TestSystemContext();

        public IQueryable<Position> Positions { get { return dbContext.Positions; } }
        public IQueryable<QuestionDifficultyToPosition> QuestionDifficultyToPositions { get { return dbContext.QuestionDifficultyToPositions; } }
        public IQueryable<QuestionTypeToPosition> QuestionTypeToPositions { get { return dbContext.QuestionTypeToPositions; } }
        public IQueryable<CategoryToPosition> CategoryToPositions { get { return dbContext.CategoryToPositions; } }
        public void addPosition(Position position)
        {
            dbContext.Positions.Add(position);
            dbContext.SaveChanges();
        }

        public void addQuestionDifficultyToPosition(QuestionDifficultyToPosition questionDifficultyToPosition)
        {
            dbContext.QuestionDifficultyToPositions.Add(questionDifficultyToPosition);
            dbContext.SaveChanges();
        }

        public void addQuestionTypeToPosition(QuestionTypeToPosition questionTypeToPosition)
        {
            dbContext.QuestionTypeToPositions.Add(questionTypeToPosition);
            dbContext.SaveChanges();
        }

        public void addCategoryToPosition(CategoryToPosition categoryToPosition)
        {
            dbContext.CategoryToPositions.Add(categoryToPosition);
            dbContext.SaveChanges();
        }

        public void RemovePosition(Position position)
        {
            dbContext.Positions.Remove(position);
            dbContext.SaveChanges();
        }

        public void RemovedQuestionDifficultyToPosition(QuestionDifficultyToPosition questionDifficultyToPosition)
        {
            dbContext.QuestionDifficultyToPositions.Remove(questionDifficultyToPosition);
            dbContext.SaveChanges();
        }

        public void RemoveQuestionTypeToPosition(QuestionTypeToPosition questionTypeToPosition)
        {
            dbContext.QuestionTypeToPositions.Remove(questionTypeToPosition);
            dbContext.SaveChanges();
        }

        public void RemoveCategoryToPosition(CategoryToPosition categoryToPosition)
        {
            dbContext.CategoryToPositions.Remove(categoryToPosition);
            dbContext.SaveChanges();
        }

        public void SaveChanges()
        {
            dbContext.SaveChanges();
        }
    }
}
